package com.browser.devtools;

import javafx.application.Platform;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class ConsolePanel {
    private final BorderPane content;
    private final TextArea console;
    private final java.text.SimpleDateFormat timeFormatter;

    public ConsolePanel() {
        this.content = new BorderPane();
        this.console = new TextArea();
        this.timeFormatter = new java.text.SimpleDateFormat("HH:mm:ss.SSS");
        
        initializeUI();
    }

    private void initializeUI() {
        console.setEditable(false);
        console.setWrapText(true);
        content.setCenter(console);
    }

    public void log(String message) {
        appendMessage("LOG", message);
    }

    public void error(String message) {
        appendMessage("ERROR", message);
    }

    private void appendMessage(String level, String message) {
        String timestamp = timeFormatter.format(new java.util.Date());
        String formattedMessage = String.format("[%s] [%s] %s\n", timestamp, level, message);
        
        Platform.runLater(() -> console.appendText(formattedMessage));
    }

    public BorderPane getContent() {
        return content;
    }
} 